package offer;

public class offerII_0014 {
    public boolean checkInclusion(String s1, String s2) {
        int len1=s1.length();
        int len2=s2.length();
        int[] num=new int[26];
        if(len2<len1) return false;
        for(int i=0;i<len1;++i){
            num[s1.charAt(i)-'a']+=1;
            num[s2.charAt(i)-'a']-=1;
        }
        if(empty(num)) return true;
        for(int i=len1;i<len2;++i){
            num[s2.charAt(i)-'a']-=1;
            num[s2.charAt(i-len1)-'a']+=1;
            if(empty(num)) return true;
        }
        return false;
    }
    public boolean empty(int[] num){
        for(int i=0;i<26;++i){
            if(num[i]!=0) return false;
        }
        return true;
    }
}
